package com.zyf.chapter02.structure.flyweight.piece.refactor;

import com.zyf.chapter02.structure.flyweight.piece.ChessPiece;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 *  * 享元模式的使用：通过工厂,对实现对享元的获取和初始化
 * @author yifeng
 */
public class ChessPieceUnitFactory {
    private static final Map<Integer, ChessPieceUnit> pieces = new HashMap<>();

    static {
        pieces.put(1, new ChessPieceUnit(1,"車", ChessPiece.Color.BLACK));
        pieces.put(2, new ChessPieceUnit(2,"馬", ChessPiece.Color.BLACK));
        // ...省略摆放其他棋子的代码...
    }

    public static ChessPieceUnit getChessPiece(int chessPieceId) {
        return pieces.get(chessPieceId);
    }
}
